﻿using SF.BLL;
using SF.Common;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;

namespace SF.Ucenter.admin.good
{
    public partial class good_edit : Web.UI.ManagePage
    {
        protected string goodExpendMsg = "";  //商品扩展信息（构造前台Html代码）
        private string action = DTEnums.ActionEnum.Add.ToString(); //操作类型
        private int id = 0;
        //页面加载事件
        protected void Page_Load(object sender, EventArgs e)
        {
            string _action = DTRequest.GetQueryString("action");

            if (!string.IsNullOrEmpty(_action) && _action == DTEnums.ActionEnum.Edit.ToString())
            {
                this.action = DTEnums.ActionEnum.Edit.ToString();//修改类型
                this.id = DTRequest.GetQueryInt("id");
                if (this.id == 0)
                {
                    JscriptMsg("传输参数不正确！", "back");
                    return;
                }
                if (!new BLL.bs_good_info().Exists(this.id))
                {
                    JscriptMsg("商品不存在或已被删除！", "back");
                    return;
                }
            }

            if (!Page.IsPostBack)
            {
                ChkAdminLevel("good_list", DTEnums.ActionEnum.View.ToString()); //检查权限

                //绑定 商品类型
                BLL.sf_goods_alltype bll = new BLL.sf_goods_alltype();
                string templatesNum = Session[DTKeys.SESSION_TEMPLATES_INFO].ToString();
                if (string.IsNullOrEmpty(templatesNum))
                {
                    JscriptMsg("请先在商品管理中选择模版！", "/admin/modeconfig/malltemplet_list.aspx");
                    return;
                }
                string where = new BLL.sf_modeconfig().GetModel("settingNum='" + templatesNum + "'").goodstype_onshelf;
                DataTable dt = bll.GetList("typeNum='" + where + "'").Tables[0];
                this.ddlGoodAllType.Items.Clear();
                this.ddlGoodAllType.Items.Add(new ListItem("请选择类型...", ""));
                foreach (DataRow dr in dt.Rows)
                {
                    this.ddlGoodAllType.Items.Add(new ListItem(dr["typeName"].ToString().Trim(), dr["typeNum"].ToString()));
                }
                if (this.ddlGoodAllType.Items.Count > 1)
                {
                    ddlGoodAllType.SelectedValue = this.ddlGoodAllType.Items[1].Value;  //默认选择通用
                    TreeBind(ddlGoodAllType.SelectedValue.ToString());  //绑定类别
                    //string msbox = "showLine(\"" + ddlGoodAllType.SelectedValue.ToString() + "\")";
                    //ClientScript.RegisterClientScriptBlock(Page.GetType(), "JsLine", msbox, true);
                }
                if (action == DTEnums.ActionEnum.Edit.ToString()) //修改
                {
                    //禁变更 所属类型 编辑
                    ddlGoodAllType.Enabled = false;
                    ShowInfo(this.id);
                }
                //新增
                else
                {
                    //从商城配置中，取得默认的返佣比例设置
                    BLL.bs_rule_config ruleConfigBll = new bs_rule_config();
                    Model.manager mgr = Session[DTKeys.SESSION_ADMIN_INFO] as Model.manager;
                    string strBusnieseNum = mgr.busnieseNum.ToString();
                    string strAppNum = Session[DTKeys.SESSION_APP_INFO].ToString();
                    string strTemplatesNum = Session[DTKeys.SESSION_TEMPLATES_INFO].ToString();
                    var ruleConfig = ruleConfigBll.GetModel(strBusnieseNum, strAppNum);
                    if (ruleConfig != null)
                    {
                        txtLevel1ReturnScale.Text = ruleConfig.level1ReturnScale.ToString();
                        txtLevel2ReturnScale.Text = ruleConfig.level2ReturnScale.ToString();
                        txtLevel3ReturnScale.Text = ruleConfig.level3ReturnScale.ToString();
                    }

                    //取得最大的排序数
                    BLL.bs_good_info goodBll = new bs_good_info();
                    string strWhere = Utils.getWhereByInfo(strBusnieseNum, strAppNum, strTemplatesNum);
                    this.txtSortId.Text = (goodBll.GetMaxSort(strWhere) + 1).ToString();
                }
                //else
                //{
                //    txtGoodsNum.Attributes.Add("ajaxurl", "../../tools/goods_ajax.ashx?action=goods_list_num_validate");
                //}
            }
            //
            if (this.IsPostBack)
            {

                //添加条件判断，防止每次重新生成商品扩展字段信息
                //if (ViewState["goodTypeId"] == null || ViewState["goodTypeId"].ToString() != ddlGoodType.SelectedValue)
                //{
                //    LoadGoodExpendHtml(ddlGoodType.SelectedValue);
                //    ViewState["goodTypeId"] = ddlGoodType.SelectedValue;
                //}

                //需要每次生成，不然点击提交的时候，无法取到控件（页面PostBack，控件丢失了）
                LoadGoodExpendHtml(ddlGoodType.SelectedValue);
            }
        }

        /// <summary>
        /// 加载商品扩展信息Html
        /// </summary>
        /// <param name="goodTypeId">商品类型Id</param>
        /// <param name="goodId">商品Id（用于取回扩展字段的值）</param>
        private void LoadGoodExpendHtml(string goodTypeId, int goodId = 0)
        {
            //先清空
            divGoodExpend.Controls.Clear();

            bs_good_type_field typeFieldBll = new bs_good_type_field();
            var typeFieldList = typeFieldBll.GetModelList(string.Format("goodTypeId='{0}'", goodTypeId));

            List<Model.bs_good_extend> goodExtendList = null;
            if (goodId > 0)
            {
                bs_good_extend goodExtendBll = new bs_good_extend();
                goodExtendList = goodExtendBll.GetModelList(string.Format("goodId='{0}'", goodId));
            }

            HtmlGenericControl dl;
            HtmlGenericControl dt;
            HtmlGenericControl dd;
            TextBox txt;
            HtmlGenericControl span;

            //动态构造dl结构
            if (typeFieldList != null && typeFieldList.Any())
            {
                foreach (Model.bs_good_type_field typeField in typeFieldList)
                {
                    string fieldCode = typeField.fieldCode;
                    string feildName = typeField.fieldName;
                    string fieldType = typeField.fieldType;
                    int? fieldLength = typeField.fieldLength;
                    int? fieldPrecision = typeField.fieldPrecision;
                    string fieldRemark = typeField.fieldRemark;

                    dl = new HtmlGenericControl("dl");
                    dl.ID = string.Format("dltxt{0}", fieldCode);
                    dl.Attributes.Add("style", "display: block");

                    dt = new HtmlGenericControl("dt");
                    dt.InnerHtml = feildName;

                    dd = new HtmlGenericControl("dd");

                    txt = new TextBox();
                    txt.ID = string.Format("txt_{0}", fieldCode);
                    txt.CssClass = "input normal";
                    txt.Attributes.Add("datatype", string.Format("*0-{0}", fieldLength));
                    if (goodId > 0)
                    {
                        txt.Text = GetGoodExtendValue(goodExtendList, fieldCode);  //从List中取得扩展字段的值
                    }

                    span = new HtmlGenericControl("span");
                    span.Attributes.Add("class", "Validform_checktip");
                    span.InnerHtml = string.Format("*最多{0}个字符 {1}", fieldLength, fieldRemark);

                    dd.Controls.Add(txt);
                    dd.Controls.Add(span);
                    dt.Controls.Add(dd);
                    dl.Controls.Add(dt);

                    divGoodExpend.Controls.Add(dl);
                }
            }

            //最后添加商品详细描述信息
            dl = new HtmlGenericControl("dl");

            dt = new HtmlGenericControl("dt");
            dt.InnerHtml = "商品描述";

            dd = new HtmlGenericControl("dd");

            //HtmlGenericControl txtContent = new HtmlGenericControl("textarea");
            //txtContent.ID = "txtContent";
            //txtContent.Attributes.Add("class", "editor");
            //txtContent.Attributes.Add("style", "visibility: hidden;");

            TextBox txtContent = new TextBox();
            txtContent.ID = "txtContent";
            txtContent.Attributes.Add("class", "editor");
            txtContent.Attributes.Add("style", "visibility: hidden;");

            dd.Controls.Add(txtContent);
            dt.Controls.Add(dd);
            dl.Controls.Add(dt);

            divGoodExpend.Controls.Add(dl);

            //<dl>
            //    <dt>商品描述</dt>
            //    <dd>
            //        <textarea id="txtContent" class="editor" style="visibility: hidden;" runat="server"></textarea>
            //    </dd>
            //</dl>

            //var txt = divGoodExpend.FindControl("txt_area") as TextBox;
            //if (txt != null)
            //{
            //    JscriptMsg(txt.Text, "");
            //}
            //else
            //{
            //    JscriptMsg("txt空了", "");
            //}


            //            goodExpendMsg = @"<dl id='dltxtArea' style='display: block'>
            //                <dt>地区</dt>
            //                <dd>
            //                    <asp:TextBox ID='txtArea' runat='server' CssClass='input normal' datatype='*2-100' sucmsg=' ' />
            //                    <span class='Validform_checktip'>*最多50个字符</span>
            //                </dd>
            //            </dl>";
        }

        private string GetGoodExtendValue(List<Model.bs_good_extend> goodExtendList, string fieldCode)
        {
            string result = string.Empty;
            if (goodExtendList != null && goodExtendList.Any())
            {
                var goodExtend = goodExtendList.FirstOrDefault(m => m.goodTypeFieldCode == fieldCode);
                if (goodExtend != null)
                {
                    result = goodExtend.fieldValue;
                }
            }
            return result;
        }
        #region 绑定类别
        private void TreeBind(string typeid)
        {
            Model.manager mgr = Session[DTKeys.SESSION_ADMIN_INFO] as Model.manager;
            string busnieseNum = mgr.busnieseNum.ToString();
            string appNum = Session[DTKeys.SESSION_APP_INFO].ToString();
            string templatesNum = Session[DTKeys.SESSION_TEMPLATES_INFO].ToString();
            BLL.bs_good_type bll = new BLL.bs_good_type();
            DataTable dt = bll.GetList(0, "goodAllTypeNum='" + typeid + "' and " + Utils.getWhereByInfo(busnieseNum, appNum, templatesNum));

            this.ddlGoodType.Items.Clear();
            this.ddlGoodType.Items.Add(new ListItem("请选择类别...", ""));
            foreach (DataRow dr in dt.Rows)
            {
                string typeId = dr["id"].ToString();
                int ClassLayer = int.Parse(dr["class_layer"].ToString());
                string Title = dr["typeName"].ToString().Trim();

                if (ClassLayer == 1)
                {
                    this.ddlGoodType.Items.Add(new ListItem(Title, typeId));
                }
                else
                {
                    Title = "├ " + Title;
                    Title = Utils.StringOfChar(ClassLayer - 1, "　") + Title;
                    this.ddlGoodType.Items.Add(new ListItem(Title, typeId));
                }
            }
        }
        #endregion

        #region 赋值操作
        private void ShowInfo(int _id)
        {
            BLL.bs_good_info bll = new BLL.bs_good_info();
            Model.bs_good_info model = bll.GetModel(_id);
            TreeBind(model.typeNum);
            #region bs_good_info basic data
            ddlGoodAllType.SelectedValue = model.typeNum;
            ddlGoodType.SelectedValue = model.goodTypeId.Value.ToString();
            LoadGoodExpendHtml(ddlGoodType.SelectedValue, _id);  //需要重新加载动态字段（此处顺便赋值）
            txtName.Text = model.name;
            //新品上架
            if (model.goodHot == "newGood")
                rblStatus_0.Checked = true;
            //精选商品
            else if (model.goodHot == "choiceGood")
                rblStatus_1.Checked = true;
            //特惠商品
            else if (model.goodHot == "preferentialGood")
                rblStatus_2.Checked = true;
            //txtValidTime.Text = model.validTime;
            field_control_market_price.Text = model.costPrice.ToString();
            field_control_sell_price.Text = model.sellPrice.ToString();
            field_control_get_price.Text = model.deletePrice.ToString();
            txtSortId.Text = model.sort.ToString();

            //txtBrandName.Text = model.brandName;
            //txtPlace.Text = model.place;
            //txtUnit.Text = model.unit;
            //txtSuitPerson.Text = model.suitPerson;
            //txtAddTime.Text = model.times;

            amountNum.Text = model.stock.ToString();  //库存

            txtZanCount.Text = model.zanCount.Value.ToString();  //点赞数
            txtStatus.Text = model.status == "onSale" ? "上架" : "下架";  //状态

            txtImgUrl.Text = model.showImage;
            imgHeadPic.ImageUrl = model.showImage;
            hidFocusPhoto.Value = model.showImage;

            //给描述赋值
            var txtContent = divGoodExpend.FindControl("txtContent") as TextBox;
            if (txtContent != null)
            {
                txtContent.Text = model.description;
            }
            #endregion

            BLL.bs_good_image imgBll = new BLL.bs_good_image();
            //获取到对应的图片列表
            DataSet ds = imgBll.GetList(" goodId='" + model.id + "'");
            if (ds.Tables[0].Rows.Count > 0)
            {
                rptAlbumList.DataSource = ds.Tables[0];
                rptAlbumList.DataBind();
            }

            #region 商品返佣设置
            BLL.bs_good_returnScale returnScaleBll = new bs_good_returnScale();
            var goodReturnScale = returnScaleBll.GetModel(" goodId='" + model.id + "'");
            if (goodReturnScale != null)
            {
                txtLevel1ReturnScale.Text = goodReturnScale.level1ReturnScale.ToString();
                txtLevel2ReturnScale.Text = goodReturnScale.level2ReturnScale.ToString();
                txtLevel3ReturnScale.Text = goodReturnScale.level3ReturnScale.ToString();
            }
            #endregion
            //if (!model.typeNum.Equals("maquillage"))
            //{
            //    //BLL.sf_goods_amounts amountsBll = new BLL.sf_goods_amounts();
            //    ////获取到商品对应 库存列表 提交给js使用
            //    //amountList = amountsBll.GetModelList("  goodsNum='" + model.goodsNum + "'");
            //    //string res = subStringAmount(amountList, model.goodsTypeNum.ToString());
            //    //string jsApp = "editset(\"" + res + "\", \"" + ddlGoodAllType.SelectedValue.ToString() + "\")";
            //    //ClientScript.RegisterClientScriptBlock(Page.GetType(), "JsSet", jsApp, true);
            //}
            //else
            //{
            //    amountNum.Text = model.stock.ToString();
            //    string jsApp = "showLine(\"" + ddlGoodAllType.SelectedValue.ToString() + "\")";
            //    ClientScript.RegisterClientScriptBlock(Page.GetType(), "JsSet", jsApp, true);
            //}
        }
        #endregion


        #region 增加操作
        private int DoAdd()
        {
            Model.manager mgr = Session[DTKeys.SESSION_ADMIN_INFO] as Model.manager;
            string strBusnieseNum = mgr.busnieseNum.ToString();
            string strAppNum = Session[DTKeys.SESSION_APP_INFO].ToString();
            string strTemplatesNum = Session[DTKeys.SESSION_TEMPLATES_INFO].ToString();

            //&&注意前台 TextBox 设置 ReadOnly 之后 后台通过ID 直接获取值
            //&&不能获取到
            int result = 1;
            Model.bs_good_info model = new Model.bs_good_info();
            BLL.bs_good_info bll = new BLL.bs_good_info();
            try
            {
                #region basic filed
                model.busnieseNum = strBusnieseNum;
                model.appNum = strAppNum;
                model.templatesNum = strTemplatesNum;
                model.typeNum = ddlGoodAllType.SelectedItem.Value;
                model.goodTypeId = Convert.ToInt64(ddlGoodType.SelectedValue);
                model.name = txtName.Text.Trim();

                if (rblStatus_0.Checked)
                    model.goodHot = "newGood";
                else if (rblStatus_1.Checked)
                    model.goodHot = "choiceGood";
                else if (rblStatus_2.Checked)
                    model.goodHot = "preferentialGood";
                model.costPrice = Utils.StrToDecimal(field_control_market_price.Text.Trim(), 0);
                model.sellPrice = Utils.StrToDecimal(field_control_sell_price.Text.Trim(), 0);
                model.deletePrice = Utils.StrToDecimal(field_control_get_price.Text.Trim(), 0);
                model.stock = Convert.ToInt32(amountNum.Text);
                model.sort = Utils.StrToInt(txtSortId.Text.Trim(), 99);

                //最后更新信息
                model.lastTime = DateTime.Now;
                model.lastUserId = mgr.id;

                model.zanCount = Convert.ToInt32(txtZanCount.Text);  //点赞数量
                model.status = txtStatus.Text == "上架" ? "onSale" : "offSale";  //上架

                //model.brandName = txtBrandName.Text.Trim();
                //model.place = txtPlace.Text.Trim();
                //model.unit = txtUnit.Text.Trim();
                //model.suitPerson = txtSuitPerson.Text.Trim();
                //model.times = DTRequest.GetFormStringValue(Request.Form["txtAddTime"].Trim(), DateTime.Now.ToString("yyyy-MM-dd"));
                //model.remark = "";

                //封面图片
                model.showImage = Request.Form["txtImgUrl"].Trim();

                //描述
                var txtContent = divGoodExpend.FindControl("txtContent") as TextBox;  //描述没取到值
                if (txtContent != null)
                {
                    model.description = txtContent.Text;
                }
                #endregion

                #region 图片上传
                List<Model.bs_good_image> ls = new List<Model.bs_good_image>();
                string[] albumArr = Request.Form.GetValues("hid_photo_name");
                string[] remarkArr = Request.Form.GetValues("hid_photo_remark");

                if (albumArr != null && albumArr.Length > 0)
                {
                    for (int i = 0; i < albumArr.Length; i++)
                    {
                        string[] imgArr = albumArr[i].Split('|');
                        if (imgArr.Length == 2 || imgArr.Length == 3)
                        {
                            ls.Add(new Model.bs_good_image { busnieseNum = mgr.busnieseNum, appNum = strAppNum, templatesNum = strTemplatesNum, remark = remarkArr[i], imageUrl = imgArr[1], id = Convert.ToInt32(imgArr[0]) });
                        }
                    }
                    model.goodImages = ls;
                }
                #endregion

                #region 商品扩展字段
                model.goodExtends = GetGoodExtendList(strBusnieseNum, strAppNum, strTemplatesNum, model.goodTypeId.Value);
                #endregion

                #region 商品返佣设置
                model.goodReturnScale = new Model.bs_good_returnScale();
                model.goodReturnScale.busnieseNum = strBusnieseNum;
                model.goodReturnScale.appNum = strAppNum;
                model.goodReturnScale.templatesNum = strTemplatesNum;
                model.goodReturnScale.level1ReturnScale = Convert.ToDecimal(txtLevel1ReturnScale.Text);
                model.goodReturnScale.level2ReturnScale = Convert.ToDecimal(txtLevel2ReturnScale.Text);
                model.goodReturnScale.level3ReturnScale = Convert.ToDecimal(txtLevel3ReturnScale.Text);
                #endregion

                if (bll.Add(model) > 0)
                {
                    AddAdminLog(DTEnums.ActionEnum.Add.ToString(), "添加商品内容:" + model.name); //记录日志
                    result = 0;
                }
            }
            catch (Exception)
            {
                result = -1;
            }
            return result;
        }
        #endregion

        #region 修改操作
        private int DoEdit(int _id)
        {
            int result = 1;
            Model.manager mgr = Session[DTKeys.SESSION_ADMIN_INFO] as Model.manager;
            string strBusnieseNum = mgr.busnieseNum.ToString();
            string strAppNum = Session[DTKeys.SESSION_APP_INFO].ToString();
            string strTemplatesNum = Session[DTKeys.SESSION_TEMPLATES_INFO].ToString();

            BLL.bs_good_info bll = new BLL.bs_good_info();
            Model.bs_good_info model = bll.GetModel(_id);
            try
            {
                #region basic data
                model.typeNum = ddlGoodAllType.SelectedItem.Value;
                model.goodTypeId = Convert.ToInt64(ddlGoodType.SelectedValue);
                model.name = txtName.Text.Trim();

                model.stock = Convert.ToInt32(amountNum.Text);

                if (rblStatus_0.Checked)
                    model.goodHot = "newGood";
                else if (rblStatus_1.Checked)
                    model.goodHot = "choiceGood";
                else if (rblStatus_2.Checked)
                    model.goodHot = "preferentialGood";

                model.costPrice = Utils.StrToDecimal(field_control_market_price.Text.Trim(), 0);
                model.sellPrice = Utils.StrToDecimal(field_control_sell_price.Text.Trim(), 0);
                model.deletePrice = Utils.StrToDecimal(field_control_get_price.Text.Trim(), 0);
                model.sort = Utils.StrToInt(txtSortId.Text.Trim(), 99);

                //model.brandName = txtBrandName.Text.Trim();
                //model.place = txtPlace.Text.Trim();
                //model.unit = txtUnit.Text.Trim();
                //model.suitPerson = txtSuitPerson.Text.Trim();
                //model.times = txtAddTime.Text.Trim();
                //model.remark = "";

                //最后更新信息
                model.lastTime = DateTime.Now;
                model.lastUserId = mgr.id;

                model.zanCount = Convert.ToInt32(txtZanCount.Text);  //点赞数量
                model.status = txtStatus.Text == "上架" ? "onSale" : "offSale";  //上架

                model.showImage = txtImgUrl.Text;
                model.showImage = Request.Form["txtImgUrl"].Trim();

                //描述
                var txtContent = divGoodExpend.FindControl("txtContent") as TextBox;  //描述没取到值
                if (txtContent != null)
                {
                    model.description = txtContent.Text;
                }
                #endregion

                #region 图片上传
                List<Model.bs_good_image> ls = new List<Model.bs_good_image>();
                string[] albumArr = Request.Form.GetValues("hid_photo_name");
                string[] remarkArr = Request.Form.GetValues("hid_photo_remark");

                if (albumArr != null && albumArr.Length > 0)
                {
                    for (int i = 0; i < albumArr.Length; i++)
                    {
                        string[] imgArr = albumArr[i].Split('|');
                        if (imgArr.Length == 2 || imgArr.Length == 3)
                        {
                            ls.Add(new Model.bs_good_image { busnieseNum = mgr.busnieseNum, appNum = strAppNum, templatesNum = strTemplatesNum, remark = remarkArr[i], imageUrl = imgArr[1], id = Convert.ToInt32(imgArr[0]) });
                        }
                    }
                    model.goodImages = ls;
                }
                #endregion

                #region 商品扩展字段
                model.goodExtends = GetGoodExtendList(strBusnieseNum, strAppNum, strTemplatesNum, model.goodTypeId.Value);
                #endregion

                #region 商品返佣设置
                model.goodReturnScale = new Model.bs_good_returnScale();
                model.goodReturnScale.busnieseNum = strBusnieseNum;
                model.goodReturnScale.appNum = strAppNum;
                model.goodReturnScale.templatesNum = strTemplatesNum;
                model.goodReturnScale.level1ReturnScale = Convert.ToDecimal(txtLevel1ReturnScale.Text);
                model.goodReturnScale.level2ReturnScale = Convert.ToDecimal(txtLevel2ReturnScale.Text);
                model.goodReturnScale.level3ReturnScale = Convert.ToDecimal(txtLevel3ReturnScale.Text);
                #endregion

                if (bll.Update(model))
                {
                    AddAdminLog(DTEnums.ActionEnum.Edit.ToString(), "修改商品内容:" + model.name); //记录日志
                    result = 0;
                }
            }
            catch (Exception)
            {
                result = -1;
            }
            return result;
        }
        #endregion

        #region 获取商品扩展信息（动态获取）
        /// <summary>
        /// 获取商品扩展字段列表
        /// </summary>
        /// <returns></returns>
        private List<Model.bs_good_extend> GetGoodExtendList(string busnieseNum, string appNum, string templatesNum, long goodTypeId)
        {
            List<Model.bs_good_extend> result = new List<Model.bs_good_extend>();

            bs_good_type_field typeFieldBll = new bs_good_type_field();
            var typeFieldList = typeFieldBll.GetModelList(string.Format("goodTypeId='{0}'", goodTypeId));

            //动态构造dl结构
            if (typeFieldList != null && typeFieldList.Any())
            {
                Model.bs_good_extend goodExtend;
                foreach (Model.bs_good_type_field typeField in typeFieldList)
                {
                    goodExtend = new Model.bs_good_extend();
                    goodExtend.busnieseNum = busnieseNum;
                    goodExtend.appNum = appNum;
                    goodExtend.templatesNum = templatesNum;
                    goodExtend.goodTypeId = goodTypeId;
                    goodExtend.goodTypeFieldCode = typeField.fieldCode;

                    //从页面取动态的控件值
                    var txt = (TextBox)this.FindControl(string.Format("txt_{0}", typeField.fieldCode));
                    if (txt != null)
                    {
                        goodExtend.fieldValue = txt.Text;
                    }
                    result.Add(goodExtend);
                }
            }
            return result;
        }
        #endregion

        //保存
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            if (action == DTEnums.ActionEnum.Edit.ToString()) //修改
            {
                ChkAdminLevel("good_list", DTEnums.ActionEnum.Edit.ToString()); //检查权限
                int res = DoEdit(this.id);
                if (res == 1)
                {
                    JscriptMsg("保存过程中发生错误啦！", "");
                    return;
                }
                else if (res == -1)
                {
                    ddlGoodAllType.SelectedValue = "";
                    JscriptShow("商品提示", "请输入合理的库存！", "");
                    return;
                }
                //string text = "savelist(\"" + txtGoodsNum.Text.Trim() + "\", \"" + this.hiddenLists.Value + "\");";
                //ClientScript.RegisterClientScriptBlock(Page.GetType(), "JsSave", text, true);
                JscriptMsg("修改信息成功！", "good_list.aspx");
            }
            else //添加
            {
                ChkAdminLevel("good_list", DTEnums.ActionEnum.Add.ToString()); //检查权限
                int res = DoAdd();
                if (res == 1)
                {
                    JscriptMsg("保存过程中发生错误啦！", "");
                    return;
                }
                else if (res == -1)
                {
                    ddlGoodAllType.SelectedValue = "";
                    JscriptShow("商品提示", "请输入合理的库存！", "");
                    return;
                }
                //string text = "savelist(\"" + txtGoodsNum.Text.Trim() + "\");";
                //ClientScript.RegisterClientScriptBlock(Page.GetType(), "JsSave", text, true);
                JscriptMsg("添加信息成功！", "good_list.aspx");
            }
        }

        /// <summary>
        /// 商品所属类型 下拉选择 
        /// </summary>
        protected void ddlGoodAllType_SelectedIndexChanged(object sender, EventArgs e)
        {
            //绑定类别
            if (!string.IsNullOrEmpty(ddlGoodAllType.SelectedValue.ToString()))
            {
                TreeBind(ddlGoodAllType.SelectedValue.ToString());
                string msbox = "showLine(\"" + ddlGoodAllType.SelectedValue.ToString() + "\")";
                ClientScript.RegisterClientScriptBlock(Page.GetType(), "JsLine", msbox, true);
            }
        }

        /// <summary>
        /// 库存信息拼接字符串
        /// 交由前台js使用
        /// </summary>
        /// <param name="list">库存信息集合</param>
        /// <returns></returns>
        //public string subStringAmount(List<Model.sf_goods_amounts> list, string goodsTypeNum)
        //{
        //    Model.manager mgr = Session[DTKeys.SESSION_ADMIN_INFO] as Model.manager;
        //    BLL.sf_goods_color colorBll = new BLL.sf_goods_color();
        //    List<Model.sf_goods_color> colors = colorBll.GetModelList("goodsTypeNum='" + goodsTypeNum + "' and " + Utils.getWhereByInfo(mgr.busnieseNum, Session[DTKeys.SESSION_APP_INFO].ToString(), Session[DTKeys.SESSION_TEMPLATES_INFO].ToString()));
        //    string msg = "";
        //    int inputId = 0;
        //    foreach (Model.sf_goods_amounts amount in list)
        //    {
        //        for (int i = 0; i < colors.Count; i++)
        //        {
        //            if (amount.colorId == colors[i].Id)
        //            {
        //                inputId = i;
        //            }
        //        }
        //        msg += amount.sizeId + "^" + inputId + "_" + amount.colorId + "_" + amount.amount + ",";
        //    }
        //    return msg;
        //}
    }
}